package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class UpdatePWD {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection()) {
            Statement statement = connection.createStatement();
            UserInfo userInfo = InputUtil.getInputObject(new UserInfo(),"修改密码","修改密码");
            String name = userInfo.getUsername();
            String pwd = userInfo.getPassword();
            String sql = "UPDATE userinfo SET password = "+pwd+" WHERE username = '"+name+"'";
            int row = statement.executeUpdate(sql);
            System.out.println(row>0?"修改成功":"修改失败");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
